package com.nongtai.service.impl;

import com.nongtai.mapper.BannerMapper;
import com.nongtai.mapper.GoodsHotRecommendMapper;
import com.nongtai.mapper.GoodsNewRecommendMapper;
import com.nongtai.pojo.entity.Banner;
import com.nongtai.pojo.entity.GoodsHotRecommend;
import com.nongtai.pojo.entity.GoodsNewRecommend;
import com.nongtai.service.FrontDataService;
import jakarta.annotation.Resource;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 前端页面普通数据相关业务
 * @author yza
 * @version 1.0
 * @date 2024/6/4 21:00
 */
@Service
public class FrontDataServiceImpl implements FrontDataService {
    @Resource
    private BannerMapper bannerMapper;
    @Resource
    private GoodsNewRecommendMapper goodsNewRecommendMapper;
    @Resource
    private GoodsHotRecommendMapper goodsHotRecommendMapper;

    /**
     * 获取轮播图数据
     * @return
     */
    @Override
    @Cacheable(cacheNames = "front",key = "'banners'")
    public List<Banner> getBanners() {
        return bannerMapper.selectList(null);
    }

    /**
     * 获取新品推荐商品
     * @return
     */
    @Override
    @Cacheable(cacheNames = "front" ,key = "'goodsNewRecommends'")
    public List<GoodsNewRecommend> getGoodsNewRecommends() {
        List<GoodsNewRecommend> goodsNewRecommends = goodsNewRecommendMapper.selectList(null);
        return goodsNewRecommends;
    }
    /**
     * 获取人气推荐商品
     * @return
     */
    @Override
    @Cacheable(cacheNames = "front" ,key = "'goodsHotRecommends'")
    public List<GoodsHotRecommend> getGoodsHotRecommends() {
        List<GoodsHotRecommend> goodsHotRecommends = goodsHotRecommendMapper.selectList(null);
        return goodsHotRecommends;
    }
}
